package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.cart.CartItem;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "购物车模块")
@RequestMapping("/api/order/cart")
public class CartController {
    @Resource
    CartService cartService;
    @Operation(summary = "获取当前用户的选中的购物项列表")
    @GetMapping("/auth/allCheckedCart")
    public Result allCheckedCart(){
        List<CartItem> list = cartService.allCheckedCart();
        return Result.ok().data(list);
    }
    @Operation(summary = "修改所有购物项选中状态")
    @GetMapping("/auth/allCheckCart/{status}")
    public Result allCheckCart(@PathVariable("status")Integer status){
        cartService.allCheckCart(status);
        return Result.ok();
    }
    @Operation(summary = "修改购物项选中状态")
    @GetMapping("/auth/checkCart/{skuId}/{status}")
    public Result checkCart(@PathVariable("skuId")Long skuId,
                            @PathVariable("status")Integer status){
        cartService.checkCart(skuId , status);
        return Result.ok();
    }
    @Operation(summary = "清空购物车")
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok();
    }

    @Operation(summary = "删除购物项")
    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCartItem(@PathVariable("skuId")Long skuId){
        cartService.deleteCartItem(skuId);
        return Result.ok();
    }


    @Operation(summary = "查询购物车")
    @GetMapping("/auth/cartList")
    public Result cartList(){
        List<CartItem> cartItemList =  cartService.cartList();
        return Result.ok().data(cartItemList);
    }
    @Operation(summary = "添加商品到购物车接口")
    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId")Long skuId ,
                            @PathVariable("skuNum")Integer skuNum){
        cartService.addToCart(skuId , skuNum);
        return Result.ok();
    }
}
